[pv console] Move console information in xenstore to serial/0/.
authorChristian Limpach <Christian.Limpach@xensource.com>
Tue, 1 May 2007 13:17:01 +0000 (14:17 +0100)
committerChristian Limpach <Christian.Limpach@xensource.com>
Tue, 1 May 2007 13:17:01 +0000 (14:17 +0100)
Support information in console/ in a backwards compatible fashion.
This puts the serial port information for pv domains at the same
location where it is for hvm domains.

Signed-off-by: Christian Limpach <Christian.Limpach@xensource.com>
tools/console/daemon/io.c

index ab8ce1280e2b721b4bca22d8c767dc2a99ea7e9a..bc2b188780f2d14cdcc0bb9ee553c84a60cd7294 100644 (file)
@@ -61,6 +61,8 @@ struct domain
        struct buffer buffer;
        struct domain *next;
        char *conspath;
+       char *serialpath;
+       int use_consolepath;
        int ring_ref;
        evtchn_port_t local_port;
        evtchn_port_t remote_port;
@@ -164,7 +166,20 @@ static int domain_create_tty(struct domain *dom)
                        tcsetattr(master, TCSAFLUSH, &term);
                }
 
-               success = asprintf(&path, "%s/limit", dom->conspath) != -1;
+               if (dom->use_consolepath) {
+                       success = asprintf(&path, "%s/limit", dom->conspath) !=
+                               -1;
+                       if (!success)
+                               goto out;
+                       data = xs_read(xs, XBT_NULL, path, &len);
+                       if (data) {
+                               dom->buffer.max_capacity = strtoul(data, 0, 0);
+                               free(data);
+                       }
+                       free(path);
+               }
+
+               success = asprintf(&path, "%s/limit", dom->serialpath) != -1;
                if (!success)
                        goto out;
                data = xs_read(xs, XBT_NULL, path, &len);
@@ -174,7 +189,7 @@ static int domain_create_tty(struct domain *dom)
                }
                free(path);
 
-               success = asprintf(&path, "%s/tty", dom->conspath) != -1;
+               success = asprintf(&path, "%s/tty", dom->serialpath) != -1;
                if (!success)
                        goto out;
                success = xs_write(xs, XBT_NULL, path, slave, strlen(slave));
@@ -182,6 +197,18 @@ static int domain_create_tty(struct domain *dom)
                if (!success)
                        goto out;
 
+               if (dom->use_consolepath) {
+                       success = asprintf(&path, "%s/tty", dom->conspath) !=
+                               -1;
+                       if (!success)
+                               goto out;
+                       success = xs_write(xs, XBT_NULL, path, slave,
+                                          strlen(slave));
+                       free(path);
+                       if (!success)
+                               goto out;
+               }
+
                if (fcntl(master, F_SETFL, O_NONBLOCK) == -1)
                        goto out;
        }
@@ -228,12 +255,20 @@ static int domain_create_ring(struct domain *dom)
 {
        int err, remote_port, ring_ref, rc;
 
-       err = xs_gather(xs, dom->conspath,
+       err = xs_gather(xs, dom->serialpath,
                        "ring-ref", "%u", &ring_ref,
                        "port", "%i", &remote_port,
                        NULL);
-       if (err)
-               goto out;
+       if (err) {
+               err = xs_gather(xs, dom->conspath,
+                               "ring-ref", "%u", &ring_ref,
+                               "port", "%i", &remote_port,
+                               NULL);
+               if (err)
+                       goto out;
+               dom->use_consolepath = 1;
+       } else
+               dom->use_consolepath = 0;
 
        if ((ring_ref == dom->ring_ref) && (remote_port == dom->remote_port))
                goto out;
@@ -301,10 +336,16 @@ static bool watch_domain(struct domain *dom, bool watch)
 
        sprintf(domid_str, "dom%u", dom->domid);
        if (watch) {
-               success = xs_watch(xs, dom->conspath, domid_str);
-               if (success)
-                       domain_create_ring(dom);
+               success = xs_watch(xs, dom->serialpath, domid_str);
+               if (success) {
+                       success = xs_watch(xs, dom->conspath, domid_str);
+                       if (success)
+                               domain_create_ring(dom);
+                       else
+                               xs_unwatch(xs, dom->serialpath, domid_str);
+               }
        } else {
+               success = xs_unwatch(xs, dom->serialpath, domid_str);
                success = xs_unwatch(xs, dom->conspath, domid_str);
        }
 
@@ -324,6 +365,15 @@ static struct domain *create_domain(int domid)
        }
 
        dom->domid = domid;
+
+       dom->serialpath = xs_get_domain_path(xs, dom->domid);
+       s = realloc(dom->serialpath, strlen(dom->serialpath) +
+                   strlen("/serial/0") + 1);
+       if (s == NULL)
+               goto out;
+       dom->serialpath = s;
+       strcat(dom->serialpath, "/serial/0");
+
        dom->conspath = xs_get_domain_path(xs, dom->domid);
        s = realloc(dom->conspath, strlen(dom->conspath) +
                    strlen("/console") + 1);
@@ -357,6 +407,7 @@ static struct domain *create_domain(int domid)
 
        return dom;
  out:
+       free(dom->serialpath);
        free(dom->conspath);
        free(dom);
        return NULL;
@@ -397,6 +448,9 @@ static void cleanup_domain(struct domain *d)
        free(d->buffer.data);
        d->buffer.data = NULL;
 
+       free(d->serialpath);
+       d->serialpath = NULL;
+
        free(d->conspath);
        d->conspath = NULL;